<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="作业单位">
        <el-input
          v-model="queryParams.deptName"
          placeholder="请输入作业单位"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="作业项目">
        <el-input
          v-model="queryParams.project"
          placeholder="请输入作业项目"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="作业时间">
        <el-date-picker
          clearable
          v-model="queryParams.beginCreateTime"
          type="datetime"
          placeholder="作业起始时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          default-time="00:00:00"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="作业场所" prop="other">
        <el-input
          v-model="queryParams.plance"
          placeholder="请输入作业场所"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['app:blastEqument:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-popconfirm
          confirm-button-text="好的"
          cancel-button-text="不用了"
          icon="el-icon-info"
          icon-color="red"
          title="确定删除吗？"
          @confirm="handleDelete"
        >
          <el-button
            v-show="activeName == 'first'"
            type="danger"
            plain
            slot="reference"
            icon="el-icon-delete"
            size="mini"
            v-hasPermi="['app:balstWork:remove']"
            >删除</el-button
          >
        </el-popconfirm>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>
    <el-tabs v-model="activeName">
      <el-tab-pane label="我发起的" name="first">
        <el-table :data="ListVehicles" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="${comment}" align="center" prop="flowNo" /> -->

          <el-table-column label="作业单位" align="center" prop="deptName" />
          <el-table-column label="人员" align="center" prop="people" />
          <el-table-column label="监护人员" align="center" prop="guardians" />
          <el-table-column label="作业项目" align="center" prop="project" />
          <el-table-column label="场所" align="center" prop="plance" />
          <el-table-column label="危险" align="center" prop="dangerous" />
          <el-table-column
            label="作业时间"
            align="center"
            prop="time"
            width="180"
          >
          </el-table-column>
          <el-table-column label="爆破员" align="center" prop="blaster" />
          <el-table-column label="安全措施" align="center" prop="security" />
          <el-table-column label="附件" align="center" prop="remark">
            <template slot-scope="scope">
              <el-button
                v-if="gettp(scope.row.remark) == 1"
                size="mini"
                type="text"
                @click="look(scope.row.remark)"
                >查看</el-button
              >
              <el-button
                v-if="gettp(scope.row.remark) == 2"
                size="mini"
                type="text"
                @click="download(scope.row.remark)"
                >下载</el-button
              >
              <span v-else></span>
            </template>
          </el-table-column>
          <el-table-column label="状态" align="center" prop="approStatus">
              <template slot-scope="scope">
                <el-tag v-if="scope.row.approStatus == 1" type="warning"
                  >待审</el-tag
                >
                <el-tag v-if="scope.row.approStatus == 2" type="success"
                  >通过</el-tag
                >
                <el-tag v-if="scope.row.approStatus == 3" type="danger"
                  >驳回</el-tag
                >
                <el-tag v-if="scope.row.approStatus == 4" type="info"
                  >撤销</el-tag
                >
              </template>
            </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="Details(scope.row.flowDetails)"
                >查看详细</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="ListVehiclestotal > 0"
          :total="ListVehiclestotal"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
      <el-tab-pane label="待我审核" name="second">
        <el-table :data="listByMyslef">
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="${comment}" align="center" prop="flowNo" /> -->

          <el-table-column label="作业单位" align="center" prop="deptName" />
          <el-table-column label="人员" align="center" prop="people" />
          <el-table-column label="监护人员" align="center" prop="guardians" />
          <el-table-column label="作业项目" align="center" prop="project" />
          <el-table-column label="场所" align="center" prop="plance" />
          <el-table-column label="危险" align="center" prop="dangerous" />
          <el-table-column
            label="作业时间"
            align="center"
            prop="time"
            width="180"
          >
          </el-table-column>
          <el-table-column label="爆破员" align="center" prop="blaster" />
          <el-table-column label="安全措施" align="center" prop="security" />
          <el-table-column label="附件" align="center" prop="remark" />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="myDetails(scope.row)"
                >去审核</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="listByMysleftotal > 0"
          :total="listByMysleftotal"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
      <el-tab-pane label="已通过" name="third">
        <el-table :data="FlowList">
          <el-table-column type="selection" width="55" align="center" />
          <!-- <el-table-column label="${comment}" align="center" prop="flowNo" /> -->

          <el-table-column label="作业单位" align="center" prop="deptName" />
          <el-table-column label="人员" align="center" prop="people" />
          <el-table-column label="监护人员" align="center" prop="guardians" />
          <el-table-column label="作业项目" align="center" prop="project" />
          <el-table-column label="场所" align="center" prop="plance" />
          <el-table-column label="危险" align="center" prop="dangerous" />
          <el-table-column
            label="作业时间"
            align="center"
            prop="time"
            width="180"
          >
          </el-table-column>
          <el-table-column label="爆破员" align="center" prop="blaster" />
          <el-table-column label="安全措施" align="center" prop="security" />
          <el-table-column label="附件" align="center" prop="remark" />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="Details(scope.row.flowDetails)"
                >查看详细</el-button
              >
            </template>
          </el-table-column>
        </el-table>
        <pagination
          v-show="FlowListtotal > 0"
          :total="FlowListtotal"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"
        />
      </el-tab-pane>
    </el-tabs>

    <!-- 添加危险 -->
    <el-dialog
      :title="title"
      :visible.sync="open"
      width="700px"
      append-to-body
      @close="openClose"
    >
      <div class="top">
        <el-steps :space="200" :active="stepIndex" finish-status="success">
          <el-step title="数据录入"></el-step>
          <el-step title="选择审批人"></el-step>
          <el-step title="部门领导审批"></el-step>
          <el-step title="高层领导审批"></el-step>
          <el-step title="发起审核"></el-step>
        </el-steps>
      </div>
      <div class="contentForm" v-if="stepIndex == 0">
        <el-form ref="form" :model="form" :rules="rules" label-width="80px">
          <el-row>
            <el-col :span="12">
              <el-form-item label="标题" prop="deptName">
                <el-input v-model="form.title" placeholder="请输入作业单位" />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="作业单位" prop="deptName">
                <el-input
                  v-model="form.deptName"
                  placeholder="请输入作业单位"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="部门">
                <el-cascader
                  placeholder="试试搜索"
                  :options="deptOptions"
                  :props="{ value: 'id' }"
                  @change="cascaderChange"
                  filterable
                ></el-cascader>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="人员" prop="people">
                <el-select
                  v-model="form.people"
                  multiple
                  collapse-tags
                  filterable
                >
                  <el-option
                    v-for="item in userSelectList"
                    :key="item.userId"
                    :label="item.nickName"
                    :value="item.nickName"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item label="监护人员" prop="guardians">
                <el-input
                  v-model="form.guardians"
                  placeholder="请输入监护人员"
                />
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="场所" prop="plance">
                <el-input v-model="form.plance" placeholder="请输入场所" />
              </el-form-item>
            </el-col>
          </el-row>

          <el-form-item label="作业项目" prop="project">
            <el-input
              v-model="form.project"
              type="textarea"
              placeholder="请输入内容"
            />
          </el-form-item>

          <el-form-item label="危险" prop="dangerous">
            <el-input
              v-model="form.dangerous"
              type="textarea"
              placeholder="请输入内容"
            />
          </el-form-item>
          <el-form-item label="作业时间" prop="time">
            <el-date-picker
              v-model="form.time"
              type="datetimerange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              align="center"
              value-format="yyyy-MM-dd HH:mm:ss"
            >
            </el-date-picker>
          </el-form-item>
          <el-form-item label="爆破员" prop="blaster">
            <el-input v-model="form.blaster" placeholder="请输入爆破员" />
          </el-form-item>
          <el-form-item label="安全措施" prop="security">
            <el-input v-model="form.security" placeholder="请输入安全措施" />
          </el-form-item>
          <el-form-item label="附件" prop="remark">
            <file-upload v-model="form.remark" />
          </el-form-item>
        </el-form>
      </div>
      <div class="contentForm" v-if="stepIndex == 1">
        <div class="topSearch">
          <el-input
            v-model="userPage.userName"
            placeholder="请输入姓名查询"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 10px; height: 40px"
          />
          <el-button
            @click="userSearch"
            type="primary"
            style="margin-bottom: 17px; height: 33px"
            >搜索</el-button
          >
        </div>
        <div class="userContent">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            node-key="id"
            default-expand-all
            highlight-current
            @node-click="handleNodeClick"
          />

          <div class="userList">
            <span
              v-for="item in userList"
              :key="item.userId"
              @click="addUser(item)"
              >{{ item.nickName }}</span
            >
          </div>

          <div class="userFooter">
            <span @click="userFooterbefor()">上一页</span>
            <span @click="userFooternext()">下一页</span>
          </div>
        </div>
        <el-divider>审批人</el-divider>
        <div class="spUser">
          <span v-for="item in checkUserList" :key="item.userId"
            >{{ item.nickName
            }}<i class="close el-icon-close" @click="userClose(item.userId)"></i
          ></span>
        </div>

        <svg
          t="1702351083987"
          class="icon"
          viewBox="0 0 34578 1024"
          version="1.1"
          xmlns="http://www.w3.org/2000/svg"
          p-id="5820"
          width="200"
          height="5"
        >
          <path
            d="M0.98794 853.827303h32873.7096v169.184757H0.98794z m32873.7096-853.580318l1704.196816 1022.765075h-1704.196816z m0 0"
            fill="#13227a"
            p-id="5821"
          ></path>
        </svg>
        <span>将按照此顺序进行审批</span>
      </div>
      <div class="contentForm" v-if="stepIndex == 2">
        <div class="topSearch">
          <el-input
            v-model="userPage.userName"
            placeholder="请输入姓名查询"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 10px; height: 40px"
          />
          <el-button
            @click="userSearch"
            type="primary"
            style="margin-bottom: 17px; height: 33px"
            >搜索</el-button
          >
        </div>
        <div class="userContent">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            node-key="id"
            default-expand-all
            highlight-current
            @node-click="handleNodeClick"
          />

          <div class="userList">
            <span
              v-for="item in userList"
              :key="item.userId"
              @click="addUser(item)"
              >{{ item.nickName }}</span
            >
          </div>

          <div class="userFooter">
            <span @click="userFooterbefor()">上一页</span>
            <span @click="userFooternext()">下一页</span>
          </div>
        </div>
        <el-divider>审批人</el-divider>
        <div class="spUser">
          <span v-for="item in checkUserList" :key="item.userId"
            >{{ item.nickName
            }}<i class="close el-icon-close" @click="userClose(item.userId)"></i
          ></span>
        </div>

        <svg
          t="1702351083987"
          class="icon"
          viewBox="0 0 34578 1024"
          version="1.1"
          xmlns="http://www.w3.org/2000/svg"
          p-id="5820"
          width="200"
          height="5"
        >
          <path
            d="M0.98794 853.827303h32873.7096v169.184757H0.98794z m32873.7096-853.580318l1704.196816 1022.765075h-1704.196816z m0 0"
            fill="#13227a"
            p-id="5821"
          ></path>
        </svg>
        <span>将按照此顺序进行审批</span>
      </div>
      <div class="contentForm" v-if="stepIndex == 3">
        <div class="topSearch">
          <el-input
            v-model="userPage.userName"
            placeholder="请输入姓名查询"
            clearable
            size="small"
            prefix-icon="el-icon-search"
            style="margin-bottom: 10px; height: 40px"
          />
          <el-button
            @click="userSearch"
            type="primary"
            style="margin-bottom: 17px; height: 33px"
            >搜索</el-button
          >
        </div>
        <div class="userContent">
          <el-tree
            :data="deptOptions"
            :props="defaultProps"
            :expand-on-click-node="false"
            :filter-node-method="filterNode"
            ref="tree"
            node-key="id"
            default-expand-all
            highlight-current
            @node-click="handleNodeClick"
          />

          <div class="userList">
            <span
              v-for="item in userList"
              :key="item.userId"
              @click="addUser(item)"
              >{{ item.nickName }}</span
            >
          </div>

          <div class="userFooter">
            <span @click="userFooterbefor()">上一页</span>
            <span @click="userFooternext()">下一页</span>
          </div>
        </div>
        <el-divider>审批人</el-divider>
        <div class="spUser">
          <span v-for="item in checkUserList" :key="item.userId"
            >{{ item.nickName
            }}<i class="close el-icon-close" @click="userClose(item.userId)"></i
          ></span>
        </div>

        <svg
          t="1702351083987"
          class="icon"
          viewBox="0 0 34578 1024"
          version="1.1"
          xmlns="http://www.w3.org/2000/svg"
          p-id="5820"
          width="200"
          height="5"
        >
          <path
            d="M0.98794 853.827303h32873.7096v169.184757H0.98794z m32873.7096-853.580318l1704.196816 1022.765075h-1704.196816z m0 0"
            fill="#13227a"
            p-id="5821"
          ></path>
        </svg>
        <span>将按照此顺序进行审批</span>
      </div>
      <div class="contentForm" v-if="stepIndex === 4">
        <el-divider>危险作业信息</el-divider>
        <el-descriptions>
          <el-descriptions-item label="作业单位">{{
            form.deptName
          }}</el-descriptions-item>
          <el-descriptions-item label="作业人员">
            <span v-for="(item, index) in form.people" :key="index">{{
              item + "."
            }}</span
            ><br />
          </el-descriptions-item>
          <el-descriptions-item label="监护人员">{{
            form.guardians
          }}</el-descriptions-item>
          <el-descriptions-item label="作业项目">{{
            form.project
          }}</el-descriptions-item>
          <el-descriptions-item label="场所">{{
            form.plance
          }}</el-descriptions-item>
          <el-descriptions-item label="危险">{{
            form.dangerous
          }}</el-descriptions-item>
          <el-descriptions-item label="爆破员">{{
            form.blaster
          }}</el-descriptions-item>
          <el-descriptions-item label="安全措施">{{
            form.security
          }}</el-descriptions-item>
          <el-descriptions-item v-if="form.time" label="作业时间">{{
            form.time[0] + "至" + form.time[1]
          }}</el-descriptions-item>
        </el-descriptions>
        <el-divider>审批人</el-divider>
        <span v-for="item in checkUserList" :key="item.userId"
          >{{ item.nickName
          }}<i class="close el-icon-close" @click="userClose(item.userId)"></i
        ></span>
      </div>

      <div slot="footer" class="dialog-footer">
        <el-button type="primary" v-if="stepIndex != 0" @click="beforTip"
          >上一步</el-button
        >
        <el-button type="primary" v-if="stepIndex != 4" @click="nextTip"
          >下一步</el-button
        >
        <el-button type="primary" v-else @click="submitForm"
          >提交审核</el-button
        >
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <!-- 详情弹出框 -->
    <el-dialog
      title="详情"
      :visible.sync="detailOpen"
      width="1100px"
      append-to-body
    >
      <el-table :data="ditailList">
        <el-table-column label="审核人" align="center" prop="name" />
        <el-table-column label="审核顺序" align="center" prop="sort" />
        <el-table-column label="审核状态" align="center" prop="status">
          <template slot-scope="scope">
            {{ myStatus[scope.row.status] }}
          </template>
        </el-table-column>
        <el-table-column label="审核意见" align="center" prop="content">
        </el-table-column>
        <el-table-column label="审核时间" align="center" prop="auditTime" />
        <el-table-column label="备注" align="center" prop="remark" />
        <el-table-column label="签名" align="center" prop="sign">
          <template slot-scope="scope">
            <!-- {{scope.row.sign}} -->
            <img
              v-if="scope.row.sign"
              style="display: block; width: 80px; height: 40px"
              :src="scope.row.sign"
            />
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <!-- 待我审核弹出框 -->
    <el-dialog :visible.sync="mydetailOpen" width="700px" append-to-body>
      <el-divider>来访信息</el-divider>
      <el-descriptions>
        <el-descriptions-item label="作业单位">{{
          mydetailData.deptName
        }}</el-descriptions-item>
        <el-descriptions-item label="作业人员">{{
          mydetailData.people
        }}</el-descriptions-item>
        <el-descriptions-item label="监护人员">{{
          mydetailData.guardians
        }}</el-descriptions-item>
        <el-descriptions-item label="作业项目">{{
          mydetailData.project
        }}</el-descriptions-item>
        <el-descriptions-item label="作业场所">{{
          mydetailData.plance
        }}</el-descriptions-item>
        <el-descriptions-item label="作业时间">{{
          mydetailData.time
        }}</el-descriptions-item>
        <el-descriptions-item label="安全措施">{{
          mydetailData.security
        }}</el-descriptions-item>
      </el-descriptions>
      <el-divider></el-divider>
      <el-form ref="form" :model="myForm" :rules="myRules" label-width="80px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="审核" prop="thing">
              <el-switch
                v-model="myForm.status"
                active-color="#13ce66"
                inactive-color="#ff4949"
                :active-value="3"
                :inactive-value="4"
                active-text="同意"
                inactive-text="不同意"
              >
              </el-switch>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="签名" prop="thing">
              <div
                @click="signLog = true"
                style="width: 200px; background-color: #d9d9d9"
              >
                <el-image
                  :src="signinimg"
                  style="
                    width: 200px;
                    height: 100px;
                    display: flex;
                    align-items: center;
                    justify-content: center;
                    color: #999;
                  "
                >
                  <div slot="error">点击签名</div>
                </el-image>
              </div>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="16">
            <el-form-item label="审核意见" prop="thing"
              ><el-input v-model="myForm.content" placeholder="请输入意见"
            /></el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item>
              <el-button type="primary" @click="mySunbit()">提交</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
    <preview-content v-if="showType" :previewMsg="previewMsg"></preview-content>
    <el-dialog title="电子签名" :visible.sync="signLog" width="700px">
      <signinDia @setsignin="setsignin"></signinDia>
    </el-dialog>
  </div>
</template>
  
  <script>
import {
  listBlastEqument,
  getBlastEqument,
  delBlastEqument,
  addBlastEqument,
  updateBlastEqument,
  blastEqumentMy,
  blastEqumentLoding,
  blastEqumentPass,
  delBalstLibrary
} from "@/api/app/balstWork";
import { listUser, deptTreeSelect } from "@/api/system/user";
import PreviewContent from "@/components/PreviewContent/PreviewContent.vue";
import cache from "@/plugins/cache";
import signinDia from "@/components/signFont/index.vue";
import { log } from '../../../components/XDVideo';
export default {
  name: "BlastEqument",
  components: {
    PreviewContent,
    signinDia,
  },
  data() {
    return {
      signinimg: null,
      signLog: false,
      stepIndex: 0,
      userId: cache.session.getJSON("userId"),
      ListVehicles: [],
      listByMyslef: [],
      FlowList: [],
      activeName: "first",
      deptOptions: [],
      userSelectList: [],
      //人员数据
      userList: [],
      previewMsg: {
        dialogTableVisible: false,
        fileType: "",
        iframeUrl: "",
      },
      showType: true,
      myStatus: {
        1: "审核中",
        2: "待我审核",
        3: "通过",
        4: "驳回",
      },
      detailStatus: {
        1: "待审核",
        2: "通过",
        3: "驳回",
        4: "撤销",
      },
      checkUserList: [],
      userPage: {
        pageNum: 1,
        pageSize: 12,
        deptId: null,
        userName: "",
      },
      defaultProps: {
        children: "children",
        label: "label",
      },
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      ListVehiclestotal: 0,
      listByMysleftotal: 0,
      FlowListtotal: 0,
      // 民爆器材领用审批表格数据
      blastEqumentList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      mydetailData: {},
      ditailList: [],
      detailOpen: false,
      mydetailOpen: false,
      myForm: {
        flowNo: null,
        status: 3,
        auditUserId: null,
        sign: null,
        id: null,
        content: "",
      },
      myRules: {},
      num: null,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        project: null,
        beginTime: null,
        deptName: null,
        plance: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        workLocation: [
          { required: true, message: "工作部位不能为空", trigger: "blur" },
        ],
        workContent: [
          { required: true, message: "工作内容不能为空", trigger: "blur" },
        ],
        usingUnit: [
          { required: true, message: "领用单位不能为空", trigger: "blur" },
        ],
      },
      flowNos: null,
    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleDelete() {
      if (this.flowNos != null && this.flowNos != "") {
        delBalstLibrary(this.flowNos).then((res) => {
          console.log(res);
          if (res.code == 200) {
            this.$modal.msgSuccess("删除成功");
            this.getList()
          }
        });
      } else {
        this.$message.error("未选择删除项");
      }
    },
    handleSelectionChange(val) {
      console.log(val);
      let flowNos = val.map((item) => {
        return item.flowNo;
      });
      this.flowNos = flowNos.join();
    },
    setsignin(img) {
      this.signinimg = img;
      this.signLog = false;
      this.myForm.sign = img;
    },
    /** 查询民爆器材领用审批列表 */
    getList() {
      this.getListVehicles();
      this.getListByMyslef();
      this.getFlowList();
    },
    // 我发起的
    async getListVehicles() {
      await blastEqumentMy({
        ...this.queryParams,
        userId: this.userId,
        type: 4,
      }).then((res) => {
        console.log(res, "我发起的");
        if (res.code == 200) {
          this.ListVehicles = res.rows;
          this.ListVehiclestotal = res.total;
        }
      });
    },

    //待审核
    async getListByMyslef() {
      await blastEqumentLoding({...this.queryParams,userId:this.userId}).then((res) => {
        console.log(res, "待审核的");
        if (res.code == 200) {
          this.listByMyslef = res.rows;
          this.listByMysleftotal = res.total;
        }
      });
    },
    // 已通过
    async getFlowList() {
      await blastEqumentPass({
        ...this.queryParams,
        approStatus: 2,
        type: 4,
        // userId: this.userId,
      }).then((res) => {
        console.log(res, "已通过的");
        if (res.code == 200) {
          this.FlowList = res.rows;
          this.FlowListtotal = res.total;
        }
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        title: null, //标题
        deptName: null, //作业单位
        people: null, //作业人员      传人员数组  (以”,“分割 ，存姓名)
        guardians: null, // 监护人员
        project: null, //作业项目
        plance: null, //场所
        dangerous: null, // 危险
        time: null, //作业时间（模板:  2023-12-12 08:00:00至_2023-12-12 15:00:00）
        blaster: null, // 爆破员
        security: null, //安全措施
        remark: null, // 附件上传
        type: 4,
      };
      this.resetForm("form");
    },
    // 添加框关闭
    openClose() {
      this.checkUserList = [];
      this.stepIndex = 0;
      this.reset();
    },
    /** 查询部门下拉树结构 */
    getDeptTree() {
      deptTreeSelect().then((response) => {
        this.deptOptions = response.data;
      });
    },
    // 查询人员
    userSearch() {
      listUser(this.userPage).then((res) => {
        this.userPage.deptId = null;
        // this.userPage.pageNum = 1;
        if (res.code == 200) {
          this.userList = res.rows;
          this.total = res.total;
        }
      });
    },
    // 人员上一页
    userFooterbefor() {
      if (this.userPage.pageNum >= 2) {
        console.log(this.userPage.pageNum);
        this.userPage.pageNum--;
        console.log(this.userPage.pageNum);
        this.userSearch();
      } else {
        this.$message("已经是第一页了");
      }
    },
    // 人员下一页

    userFooternext() {
      if (this.userPage.pageNum < Math.ceil(this.total / 12)) {
        this.userPage.pageNum++;
        console.log(this.userPage.pageNum);
        this.userSearch();
      } else {
        this.$message("已经是最后一页了");
      }
    },
    //上一步
    beforTip() {
      this.stepIndex--;
    },
     //下一步
     nextTip() {
      if (this.stepIndex == 0) {
        this.getDeptTree();
      } else if (this.stepIndex == 4) {
        return;
      }
      this.stepIndex++;
      console.log(this.stepIndex);
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.userPage.deptId = data.id;

      this.userPage.pageNum = 1;

      this.userSearch();
    },
    //添加审批人
    addUser(item) {
      if (
        JSON.stringify(this.checkUserList).indexOf(JSON.stringify(item)) === -1
      ) {
        this.checkUserList.push(item);
      } else {
        this.$message.error("该审批人已经存在");
      }
    },
    cascaderChange(data) {
      console.log(data);
      // pageNum=1&pageSize=6&peopleType=1&deptId=105
      listUser({
        deptId: data[data.length - 1],
        // pageNum: 1,
        // pageSize: 1,
        peopleType: 1,
      }).then((res) => {
        this.userSelectList = res.rows;
      });
    },
    //待我审核详细
    myDetails(data) {
      console.log(data);

      this.myForm.flowNo = data.flowNo;
      this.myForm.id = data.id;
      this.mydetailOpen = true;
      this.mydetailData = data;

      // this.myForm.flowNo = flowNo;
      // this.myForm.id = id;
      // getBlastEqument(flowNo).then((res) => {
      //   console.log(res);
      //   this.mydetailOpen = true;
      //   this.mydetailData = res.data;
      // });
    },
    // 删除审批用户
    userClose(id) {
      this.checkUserList.some((item, i) => {
        if (item.userId === id) {
          this.checkUserList.splice(i, 1);
        }
      });
    },
    // 提交审批
    submit() {
      let data = { ...this.form };
      data.userId = this.userId;
      // data.approStatus = 1;
      data.type = 4;

      // data.time =
      data.flowDetails = [];
      this.checkUserList.forEach((item, index) => {
        data.flowDetails.push({ auditUserId: item.userId, sort: index + 1 });
      });
      vehicles(data).then((res) => {
        if (res.code == 200) {
          this.$modal.msgSuccess("提交成功");
          this.open = false;
          this.reset();
          this.stepIndex = 0;
          this.checkUserList = [];
          this.getList();
        } else {
          this.open = false;
          this.reset();
          this.stepIndex = 0;
          this.checkUserList = [];
          this.getList();
          this.$message.error("提交失败");
        }
      });
    },
    // 我的审核
    mySunbit() {
      this.myForm.auditUserId = this.userId;
      updateBlastEqument(this.myForm).then((res) => {
        if (res.code == 200) {
          this.$message("审批完成");
        } else {
          this.$message.error("失败");
        }
        this.mydetailOpen = false;
        this.getList();
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      (this.queryParams = {
        pageNum: 1,
        pageSize: 10,
        project: null,
        beginTime: null,
        deptName: null,
        plance: null,
      }),
        this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    // handleSelectionChange(selection) {
    //   this.ids = selection.map((item) => item.flowNo);
    //   this.single = selection.length !== 1;
    //   this.multiple = !selection.length;
    // },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.getDeptTree();
      this.open = true;
      this.title = "添加危险作业审批";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const flowNo = row.flowNo || this.ids;
      getBlastEqument(flowNo).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改民爆器材领用审批";
      });
    },
    /** 提交按钮 */
    submitForm() {
      //   this.$refs["form"].validate((valid) => {
      // if (valid) {
      if (this.form.flowNo != null) {
        updateBlastEqument(this.form).then((response) => {
          this.$modal.msgSuccess("修改成功");
          this.open = false;
          this.getList();
        });
      } else {
        let data = { ...this.form };
        data.userId = this.userId;
        //data.approStatus = 1;
        data.type = 4;
        data.people = data.people.join();

        data.time = data.time[0] + "至" + data.time[1];

        data.flowDetails = [];
        this.checkUserList.forEach((item, index) => {
          data.flowDetails.push({
            auditUserId: item.userId,
            sort: index + 1,
          });
        });

        addBlastEqument(data).then((res) => {
          if (res.code == 200) {
            this.$modal.msgSuccess("提交成功");
            this.open = false;
            this.reset();
            this.stepIndex = 0;
            this.checkUserList = [];
            this.getList();
          } else {
            this.open = false;
            this.reset();
            this.stepIndex = 0;
            this.checkUserList = [];
            this.getList();
            this.$message.error("提交失败");
          }
        });
      }
      // }
      //   });
    },
    // 查看来访详细
    Details(data) {
      console.log(data);
      this.detailOpen = true;
      this.ditailList = data;
    },
    /** 删除按钮操作 */
    // handleDelete(row) {
    //   const flowNos = row.flowNo || this.ids;
    //   this.$modal
    //     .confirm(
    //       '是否确认删除民爆器材领用审批编号为"' + flowNos + '"的数据项？'
    //     )
    //     .then(function () {
    //       return delBlastEqument(flowNos);
    //     })
    //     .then(() => {
    //       this.getList();
    //       this.$modal.msgSuccess("删除成功");
    //     })
    //     .catch(() => {});
    // },
    /** 导出按钮操作 */
    handleExport() {
      this.download(
        "app/blastEqument/export",
        {
          ...this.queryParams,
        },
        `blastEqument_${new Date().getTime()}.xlsx`
      );
    },
    gettp(v) {
      if (v == null || v == "") {
        return 0;
      }
      let type = null;
      if (v.includes(",")) {
        let list = v.split(",");
        list.forEach((item) => {
          type = this.getFileType(item);
        });
      } else {
        type = this.getFileType(v);
      }
      if (type == "pdf" || type == "txt") {
        return 1;
      } else {
        return 2;
      }
    },
    getFileType(url) {
      let pdfReg = /^.+(\.pdf)$/;
      let txtReg = /^.+(\.txt)$/;
      let wordReg = /^.+(\.doc|\.docx)$/;
      let excelReg = /^.+(\.xls|\.xlsx)$/;
      let jpgReg = /^.+(\.png|\.jpg|\.jpeg|\.bmp)$/;
      if (pdfReg.test(url)) {
        return "pdf";
      }
      if (txtReg.test(url)) {
        return "txt";
      }
      if (wordReg.test(url)) {
        return "word";
      }
      if (excelReg.test(url)) {
        return "excel";
      }
      if (jpgReg.test(url)) {
        return "picture";
      }
    },
    look(v) {
      this.showType = false;
      this.$nextTick(() => {
        this.showType = true;
      });
      let list = v.split(",");
      this.previewMsg.dialogTableVisible = true;
      this.previewMsg.iframeUrl = list[0];
    },
  },
  download(value) {
    if (value.indexOf(",") >= 0) {
      let split = value.split(",");
      for (var i = 0; i < split.length; i++) {
        if (split[i] != "") {
          let num = split[i].lastIndexOf(".");
          let dis = split[i].substring(num + 1, num + 4);

          if (dis == "pdf" || dis == "PDF") {
            downloadFile(split[i], "a");
          } else {
            downloadFile(split[i], "iframe");
          }
        }
      }
    } else {
      let num = value.lastIndexOf(".");
      let dis = value.substring(num + 1, num + 4);
      if (dis == "pdf" || dis == "PDF") {
        downloadFile(value, "a");
      } else {
        downloadFile(value, "iframe");
      }
    }
  },
};
</script>
<style lang='scss' scoped>
.el-tree {
  width: 30%;
}
.topSearch {
  display: flex;
  align-items: center;
}
.userContent {
  display: flex;
}
.userList {
  display: inline-grid;
  grid-template-columns: 100px 100px 100px 100px;
  // grid-template-rows: 50px 50px;
  grid-gap: 5px;
  width: 70%;
  height: 100%;
  span {
    // width: 25%;
    padding: 8px;
    text-align: center;
    background-color: #ccc;
  }
}

.userFooter {
  position: absolute;
  right: 0;
  top: 500px;
  span {
    margin: 20px;
    color: #1890ff;
    cursor: pointer;
  }
}
.spUser {
  display: flex;
  span {
    position: relative;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: #27aa07;
    color: aliceblue;
    margin: 6px;
    text-align: center;
    line-height: 50px;

    .close {
      position: absolute;
      color: #000;
      top: 0;
      right: -5px;
      font-weight: 700;
      cursor: pointer;
      display: none;
    }
  }
  span:hover .close {
    display: block;
  }
}
</style>